package com.javaGame.frame;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * 菜单窗体
 */
public class MenuFrame extends JFrame implements KeyListener {
    /**玫瑰花图片*/
    private ImageLabel roseImg = new ImageLabel("image/menuRose.png",
            100,350,100,50,this);
    /**玫瑰花起始Y坐标*/
    private int y = 350;

    public MenuFrame(){
        this.setLayout(null);

        new ImageLabel("image/menu.jpg",
                0,0,1000,700,this);

        //注册键盘事件
        this.addKeyListener(this);

        this.setSize(1000,700);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }
    public static void main(String[] args) {
        new MenuFrame();
    }

    @Override
    public void keyTyped(KeyEvent e) {}

    @Override
    public void keyPressed(KeyEvent e) {}

    @Override
    public void keyReleased(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if(keyCode == KeyEvent.VK_DOWN){
            //Y坐标增加
            y += 100;
            //到达最后选项时，回到第一选项
            if(y > 550){
                y = 350;
            }
            //重新设置图片位置
            roseImg.setLocation(100,y);
        }
        else if(keyCode == KeyEvent.VK_ENTER){
            if(y == 350){//开始游戏
                //卸载窗体
                this.dispose();
                new MainFrame();
            }
            else if(y == 450){//排行榜
                this.dispose();
                new SortFrame();
            }
            else if(y == 550){//结束游戏
                System.exit(0);
            }
        }
    }
}
